package org.qpcr.community.project.web;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.web.api.crud.entity.PagerResult;
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.authorization.annotation.QueryAction;
import org.hswebframework.web.authorization.annotation.Resource;
import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
import org.hswebframework.web.exception.NotFoundException;
import org.qpcr.community.device.entity.DeviceInstanceEntity;
import org.qpcr.community.project.model.entity.RelateDeptAndDeviceEntity;
import org.qpcr.community.project.model.entity.RelateProItemSeqInstanceEntity;
import org.qpcr.community.project.response.RelateProItemSeqDetail;
import org.qpcr.community.project.response.RelateProItemSeqDetailSync;
import org.qpcr.community.project.service.LocalRelateDeptDeviceInstanceService;
import org.qpcr.community.project.service.LocalRelateProItemSeqInstanceService;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

/**
 * 部门关联设备关系对象
 */
@RestController
@RequestMapping( {"/project/relate-dept-device", "/project/relate/dept/device"})
@Authorize
@Resource(id = "relate-dept-device", name = "部门关联设备关系对象")
@Slf4j
@Tag(name = "部门关联设备关系对象")
@RequiredArgsConstructor
public class RelateDeptDeviceController implements
    ReactiveServiceCrudController<RelateDeptAndDeviceEntity, String> {
    @Getter
    private final LocalRelateDeptDeviceInstanceService service;

//    /**
//     * 分页获取详情
//     *
//     * @param query query
//     * @return Mono<PagerResult<RelateProItemSeqDetail>>
//     */
//    @PostMapping("/_query/paging-detail/{type:.+}")
//    @QueryAction
//    @Operation(summary = "分页获取详情")
//    public Mono<PagerResult<DeviceInstanceEntity>> queryRelateProItemSeqDetail(@RequestBody Mono<QueryParamEntity> query) {
//        return query.flatMap(q -> service
//                .queryRelateDeptToDeviceList(q)
//                .switchIfEmpty(Mono.error(NotFoundException::new)));
//    }

//    @GetMapping("/query-to-device/{devideId:.+}")
//    @QueryAction
//    @Operation(summary = "查询未同步设备的产品关联的检测项和检测序列")
//    @Authorize(ignore = true)
//    public Mono<Map<String, List<RelateProItemSeqDetailSync>>> queryToDevice(@PathVariable String devideId, Long lastUpdateTime) {
//        return service.queryToDevice(false, devideId, lastUpdateTime);
//    }
//
//    @PostMapping("/sync-to-device/{devideId:.+}")
//    @QueryAction
//    @Operation(summary = "同步设备的产品关联的检测项和检测序列")
//    @Authorize(ignore = true)
//    public Mono<Map<String, List<RelateProItemSeqDetailSync>>> syncToDevice(@PathVariable String devideId, Long lastUpdateTime) {
//        return service.syncToDevice(devideId, lastUpdateTime);
//    }
}
